<template>
  <div>
    <div>
      <h2>未审核订单</h2>
    </div>
    <!-- 表格渲染 -->
    <el-table
      border
      :fit="true"
      ref="tableData"
      max-height="750"
      style="width: 100%"
      :data="tableData"
      
    >
      <el-table-column type="index" label="序号" width="60"></el-table-column>
      <el-table-column prop="u_id" v-if="false"></el-table-column>
      <el-table-column prop="order_id" label="订单号"></el-table-column>
      <el-table-column prop="roomNumber" label="订房数量"></el-table-column>
      <el-table-column prop="Status" label="状态" :formatter="orderStatus"></el-table-column>
      
      <el-table-column prop="orderTime" label="订单时间" width="160"></el-table-column>
      <el-table-column prop="arrireDate" label="到达时间" width="160"></el-table-column>
      <el-table-column prop="leaveDate" label="离开时间" width="160"></el-table-column>
      <el-table-column prop="realMoney" label="实收（元）"></el-table-column>
      <el-table-column prop="orderMoney" label="定价（元）"></el-table-column>
      <el-table-column prop="userPhone" label="手机号" width="170"></el-table-column>
      <el-table-column prop="user_remark" label="用户备注"></el-table-column>
      <el-table-column prop="admin_remark" label="备注"></el-table-column>
      <el-table-column fixed="right" label="操作" width="240">
        <template slot-scope="scope">
          <el-button
            size="medium"
            type="text"
            @click="approve(scope.$index,scope.row)"
            :disabled="scope.row.checkInVisible"
          >审核通过</el-button>
          <el-button
            size="medium"
            type="text"
            @click="refuse(scope.$index,scope.row)"
            :disabled="scope.row.checkOutVisible"
          >审核不通过</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  data(){
    return{
        tableData: [],
        roomInfo:{
          order_id:'',
          order_Status:'',
        },
    }
  },
    mounted () {
    this.getHome()
  },
  methods:{
    orderStatus(row) {
          console.log(row);
          if (row.orderStatus == 0) {
              row.Status = "未审核";
              return row.Status;
          } else if (row.orderStatus == 1) {
              row.Status = "审核通过";
              return row.Status;
          } else if (row.orderStatus == 2) {
              row.Status = "已入住";
              return row.Status;
          } else if (row.orderStatus == -1) {
              row.Status = "用户取消订单";
              return row.Status;
          } else if (row.orderStatus == -2) {
              row.Status = "拒绝";
              return row.Status;
          }
      },
    getHome(){
      
      this.$axios.get("/ssms/admin/order/getOrderByStatus?orderStatus=0",{headers:{'Content-Type':'application/json',
      responseType: "application/json"}})
      .then(res => {
        console.log(res.data);
        if(res.data.code === 0){
          this.tableData = res.data.obj;
          
        }
      })
  },
  approve(index, row){
    this.roomInfo.order_id = row.order_id;
    this.roomInfo.order_Status = 1;
    var data = JSON.stringify(this.roomInfo);
    this.$axios.post("/ssms/admin/order/checkUserOrder", data,{headers:{'Content-Type':'application/json',
      responseType: "application/json"}})
      .then(res => {
        console.log(res.data);
        if(res.data.code === 0){
          alert(res.data.msg);
          this.getHome();
        }else{
          alert(res.data.msg);
          this.getHome();
        }
      })
  },
  refuse(index, row){
    this.roomInfo.order_id = row.order_id;
    this.roomInfo.order_Status = -2;
    var data = JSON.stringify(this.roomInfo);
    console.log(data);
    this.$axios.post("/ssms/admin/order/checkUserOrder",data,{headers:{'Content-Type':'application/json',
      responseType: "application/json"}})
      .then(res => {
        console.log(res.data);
        if(res.data.code === 0){
          alert("订单审核不通过");
          this.getHome();
        }else{
          alert(res.data.msg);
          this.getHome();
        }
      })
  }
  }
};
</script>

<style>
</style>